package com.shuma.shopmanage.shopmodule.service.serviceImpl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shuma.shopmanage.shopmodule.mapper.GoodsProxyMapper;
import com.shuma.shopmanage.shopmodule.service.GoodsProxyService;
import com.shuma.shopmanage.model.shop.model.GoodsProxy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author wp
 * @data 2023/10/24
 */
@Service
public class GoodsProxyServiceImpl extends ServiceImpl<GoodsProxyMapper, GoodsProxy> implements GoodsProxyService {

    @Autowired
    GoodsProxyMapper goodsProxyMapper;
    /**
     * 根据用户名查代理商品Id
     * @param userId
     * @return
     */
    @Override
    public List<Long> selectGoodsIdsByUid(Long userId) {
        List<GoodsProxy> goodsProxies = query().
                eq("proxyId", userId).list();
        List<Long> goodsIds = goodsProxies.stream().map
                (GoodsProxy::getGoodsId).collect(Collectors.toList());
        return goodsIds;
    }

    @Override
    public GoodsProxy getGoodsProxy(Long goodsId, Long userId) {
        GoodsProxy goodsProxy = goodsProxyMapper.getGoodsProxy(goodsId, userId);
        return goodsProxy;
    }
}
